<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function hex2bin($hexdata) {
	$bindata="";
	
	for ($i=0;$i<strlen($hexdata);$i+=2) {
	$bindata.=chr(hexdec(substr($hexdata,$i,2)));
	}

	return $bindata;
}

function decrypt($mes, $secret_key){

	$cipher     = "rijndael-128";
	$mode       = "cbc";
	//$secret_key = "01234567890abcde";
	$iv         = "fedcba9876543210";
	
	$td = mcrypt_module_open($cipher, "", $mode, $iv);
	
	mcrypt_generic_init($td, $secret_key, $iv);
	$decrypted_text = mdecrypt_generic($td, hex2bin($mes));
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	
	$result = trim(substr($decrypted_text,16,strlen($decrypted_text)-10));
	return $result;

}
 